<?php

namespace app\admin\model;

use app\common\model\Config;
use think\Model;


class Video extends Model
{


    // 表名
    protected $name = 'community';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;
    protected $resultSetType = 'collection';

    // 追加属性
    protected $append = [

    ];

    //label
    public function labels()
    {
        return $this->belongsTo('label', 'label', 'id', '', 'left')->setEagerlyType(0);
    }


    public function getVideoImageAttr($video, $data)
    {
        return cdnurl($data['video_image']);

    }



    public function getImagesAttr($value, $data)
    {

        $arr = explode(',', $data['images']);
        foreach ($arr as &$item) {

                $item = cdnurl( $item);

        }
        return $arr;
    }

    public function getAvatarImageAttr($value, $data)
    {
        return cdnurl($value);

    }

    public function getAskImageAttr($value, $data)
    {
        return cdnurl($data['ask_image']);

    }

    public function user()
    {
        return $this->belongsTo('user', 'user_id', 'id', [], 'Left');
    }

    public function getVideoAttr($name)
    {

        $vide_prefix = Config::where('name', 'video_prefix')->value('value');
        if ($vide_prefix != '') {
            return $vide_prefix . substr($name, 24);
        }
        return $name;
    }


}
